package com.hrpmar.controller;


import com.hrpmar.pojo.Department;
import com.hrpmar.pojo.Role;
import com.hrpmar.service.powerServer;
import com.sun.tools.internal.ws.processor.model.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import java.util.List;

import static com.sun.tools.attach.VirtualMachine.list;

/**
 * Created by 李松松 on 2017/12/4.
 */
@Controller
@RequestMapping("/sys/function")
public class PowerController {



    @Resource
    private powerServer powerserver;

    @RequestMapping("/list")
    @ResponseBody
    public List<Department> search(){
        List<Department> lists= powerserver.list();
        return lists;
    }
    @RequestMapping("/powers")
    @ResponseBody
    public List<Role> searchId(Integer id){
        System.out.println("id="+id);
        List<Role> parentId=  powerserver.lists(id);
        return parentId;
    }

    @PostMapping("/editMenu")
    @ResponseBody
    public String editMenu(Department func){
        String msg = null;
        try{
            if (powerserver.updates(func)>0){
                msg= "修改成功";
            }else {
                msg="修改失败";
            }
        }catch (RuntimeException e){
            msg="修改失败";
        }
        return msg;
    }
    @PostMapping("/searchId")
    @ResponseBody
    public Department searchIdby(Integer ids){
        return powerserver.searchIdby(ids);
    }

    @RequestMapping("/inserts")
    @ResponseBody
    public String inserts(Department func){
        String msg=null;
        try{
            if (powerserver.inserts(func)>0){
                msg="添加成功";
            }
        }catch (RuntimeException e){
            msg="增加失败";
        }
        return msg;
    }
    @RequestMapping("/playadd")
    @ResponseBody
    public String playadd(Role role){
        String msg=null;
        try{
            if (powerserver.playadd(role)>0){
                msg="增加角色成功";
            }
        }catch (RuntimeException e){
            msg="增加角色失败";
        }
        return msg;
    }
    @RequestMapping("/roleUpdate")
    @ResponseBody
    public String roleUpdate(Role role){
        String msg=null;
        try{
            if (powerserver.roleUpdate(role)>0){
                msg="修改角色成功";
            }
        }catch (RuntimeException e){
            msg="修改角色失败";
        }
        return msg;
    }
    @RequestMapping("/getFunc")
    @ResponseBody
    public Integer del(Integer roleId) {
        return powerserver.del(roleId);
    }




}
